package com.servlet;

import com.dao.GoodsDAO;
import com.model.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/listGoods")
public class ListGoodsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsDAO goodsDAO = new GoodsDAO();
        List<Goods> goodsList = goodsDAO.getAllGoods();
        System.out.println(goodsList);
        HttpSession httpSession = request.getSession();
        httpSession.setAttribute("goodsList", goodsList);
        response.sendRedirect("listGoods.jsp");
        //request.setAttribute("goodsList", goodsList);
        //request.getRequestDispatcher("listGoods.jsp").forward(request, response);
    }
}
